feat: add key/value allowlisting to OperationContext#181
Open
arorashivam96 wants to merge 1 commit into
Open
Conversation
Validate that operation_context keys are from {app, skill, agent} and
values match their respective allowlists. Unknown keys like 'ssn' or
'name' are rejected with ValueError. This prevents PII from entering
the User-Agent header even from standalone callers outside the plugin.
- skill values must be in the 7 known Dataverse skills
- agent values must be in {claude-code, copilot, cursor, codex, unknown}
- app values must match <name>/<version> format
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a closed allowlist for OperationContext.user_agent_context so only the keys app, skill, and agent are accepted, with values for skill and agent constrained to known identifier sets and app constrained to a <name>/<version> pattern. This hardens the SDK against PII leaking into the User-Agent header from standalone callers, on top of the existing structural validation.
Changes:
- Introduces
_ALLOWED_KEYS,_ALLOWED_SKILLS,_ALLOWED_AGENTS, and_APP_PATTERNconstants incore/config.py. - Adds a per-pair allowlist validation loop in
OperationContext.__post_init__plus updated docstring. - Adds 5 negative unit tests covering unknown keys, unknown skill, unknown agent, PII-shaped input, and malformed
appvalues.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/PowerPlatform/Dataverse/core/config.py |
Adds allowlist constants, app-value regex, validation loop, and updates docstring/raises notes. |
tests/unit/test_operation_context.py |
Adds 5 tests asserting ValueError for unknown keys/values and invalid app format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OperationContext.__post_init__so that only known keys (app,skill,agent) and their respective allowlisted values are accepted--context "ssn=123-45-6789"is now rejected at the SDK layer)What's validated
app<name>/<version>formatdataverse-skills/1.5.0noslashskilldv-datanot-a-skillagentclaude-codenot-an-agentssn=123-45-6789Changes
src/.../core/config.py_ALLOWED_KEYS,_ALLOWED_SKILLS,_ALLOWED_AGENTS,_APP_PATTERN; key/value validation loop in__post_init__tests/unit/test_operation_context.pyTest plan
pytest tests/unit/test_operation_context.py -v— 25 passedpytest tests/unit/ -v— 1394 passed, 0 regressionsblack src tests --check— clean🤖 Generated with Claude Code